﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GrayParrot.Communications.Configuration
{
    /// <summary>
    /// 
    /// </summary>
    /// <seealso cref="System.Configuration.ConfigurationElementCollection" />
    public class EmailsCollection : ConfigurationElementCollection
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="EmailsCollection"/> class.
        /// </summary>
        public EmailsCollection()
        {
        }

        /// <summary>
        /// Gets the <see cref="EmailItem"/> with the specified identifier.
        /// </summary>
        /// <value>
        /// The <see cref="EmailItem"/>.
        /// </value>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public EmailItem this[int id]
        {
            get
            {
                return this.OfType<EmailItem>().FirstOrDefault(item => item.Key == id);
            }
        }

        /// <summary>
        /// Adds the specified item configuration.
        /// </summary>
        /// <param name="itemConfig">The item configuration.</param>
        public void Add(EmailItem itemConfig)
        {
            BaseAdd(itemConfig);
        }

        /// <summary>
        /// Clears this instance.
        /// </summary>
        public void Clear()
        {
            BaseClear();
        }

        /// <summary>
        /// When overridden in a derived class, creates a new <see cref="T:System.Configuration.ConfigurationElement" />.
        /// </summary>
        /// <returns>
        /// A new <see cref="T:System.Configuration.ConfigurationElement" />.
        /// </returns>
        protected override ConfigurationElement CreateNewElement()
        {
            return new EmailItem();
        }

        /// <summary>
        /// Gets the element key for a specified configuration element when overridden in a derived class.
        /// </summary>
        /// <param name="element">The <see cref="T:System.Configuration.ConfigurationElement" /> to return the key for.</param>
        /// <returns>
        /// An <see cref="T:System.Object" /> that acts as the key for the specified <see cref="T:System.Configuration.ConfigurationElement" />.
        /// </returns>
        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((EmailItem)element).Key;
        }

        /// <summary>
        /// Removes the specified item configuration.
        /// </summary>
        /// <param name="itemConfig">The item configuration.</param>
        public void Remove(EmailItem itemConfig)
        {
            BaseRemove(itemConfig.Key);
        }

        /// <summary>
        /// Removes at.
        /// </summary>
        /// <param name="index">The index.</param>
        public void RemoveAt(int index)
        {
            BaseRemoveAt(index);
        }

        /// <summary>
        /// Removes the specified name.
        /// </summary>
        /// <param name="name">The name.</param>
        public void Remove(string name)
        {
            BaseRemove(name);
        }
    }
}
